package ws.very.util.lang

import scala.util.Try
import scala.collection.immutable.StringOps

trait WeekTypeCookies {

  implicit def toLong(p: String): Long =
    try2Parse(p, 0L) { _.toLong }

  private def try2Parse[T](str: String, defalut: T = 0)(fn: StringOps => T) =
    Try {
      fn(augmentString(str))
    }.getOrElse(defalut)

  implicit def toInt(p: String): Int =
    try2Parse(p) { _.toInt }

  implicit def toBool(p: String): Boolean =
    try2Parse(p, false) { _.toBoolean }

}

object AutoAsTypeUtil {
  implicit def any2any[T](any: Any) = any.asInstanceOf[T]
}